<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img src="img/bulboff.gif" alt="灯">
<br><hr>
<input type="button" value="开" onclick="openBul(event)">
//<input type="text" id="dd1">
</body>
<script>
    function openBul(e) {
        //document.getElementById('dd1').value = '22';
        let bulb = document.getElementsByTagName('img')[0];
        bulb.setAttribute('src','img/bulbon.gif');
        e.target.value='关';
        e.target.setAttribute('onclick','offBul(this)')//this代表当前对象，即input对象
    }
    function offBul(obj) {
        let bulb = document.getElementsByTagName('img')[0];
        bulb.setAttribute('src','img/bulboff.gif');
        obj.value='开';
        obj.setAttribute('onclick','openBul(event)')
    }
</script>
</html>